package view;

import controllers.PersonalInformationControllers;
import entity.User;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 * @author zjw
 * @date 2020/1/4 9:46
 */
public class PersonalInformationInterface {
    private Stage primaryStage;
    private Label idLabel = new Label("账号：");
    private Label mottoLabel = new Label("签名：");
    private Label nameLabel = new Label("姓名：");
    private Label ageLabel = new Label("年龄：");
    private Label genderLabel = new Label("性别");
    private Label addressLabel = new Label("家乡：");
    private Label telNumLabel = new Label("电话：");
    private Text idText;
    private TextArea mottoTextArea;
    private Text nameText;
    private Text ageText;
    private Text genderText;
    private Text addressText;
    private Text telNumText;
    private ImageView headPortraitImageView;
    private GridPane gridPane;
    private User user;

    public PersonalInformationInterface(User user, Stage primaryStage, int jud) {
        // 获取当前正在运行的线程账号
        this.user = user;
        this.primaryStage = primaryStage;
        gridPane = new GridPane();
        idText = new Text();
        mottoTextArea = new TextArea();
        nameText = new Text();
        ageText = new Text();
        genderText = new Text();
        addressText = new Text();
        telNumText = new Text();

        if(jud == 1) {
            PersonalInformationControllers personalInformationControllers = new PersonalInformationControllers(user, primaryStage);
            Button editorButton = personalInformationControllers.getEditorButton();
            gridPane.add(editorButton, 1, 8);
        }

        idText.setText(this.user.getId());
        mottoTextArea.setText(this.user.getMotto());
        nameText.setText(this.user.getName());
        ageText.setText(this.user.getAge());
        genderText.setText(this.user.getGender());
        addressText.setText(this.user.getAddress());
        telNumText.setText(this.user.getTelNum());

    }

    public void start() throws Exception {
        initInterface();

        Scene scene = new Scene(gridPane);
        primaryStage.setScene(scene);
        primaryStage.setWidth(350);
        primaryStage.setHeight(500);
        primaryStage.setTitle("编辑信息");
        primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("../image/Home.jpg")));
        primaryStage.show();
    }

    /**
     * 初始化界面布局信息
     */
    private void initInterface() {

        mottoTextArea.setEditable(false);
        mottoTextArea.setWrapText(true);
        mottoTextArea.setPrefWidth(100);
        mottoTextArea.setPrefHeight(50);

        Image headPortraitImage = new Image(getClass().getResourceAsStream("../image/Home.jpg"));
        headPortraitImageView = new ImageView(headPortraitImage);
        headPortraitImageView.setFitWidth(100);
        headPortraitImageView.setFitHeight(100);

        gridPane.setAlignment(Pos.CENTER);
        gridPane.setVgap(20);
        gridPane.setHgap(20);
        gridPane.setPadding(new Insets(20, 20, 20, 20));
        gridPane.add(headPortraitImageView, 1, 0);
        gridPane.add(idLabel, 0, 1);
        gridPane.add(idText, 1, 1);
        gridPane.add(mottoLabel, 0, 2);
        gridPane.add(mottoTextArea, 1, 2);
        gridPane.add(nameLabel, 0, 3);
        gridPane.add(nameText, 1, 3);
        gridPane.add(ageLabel, 0, 4);
        gridPane.add(ageText, 1, 4);
        gridPane.add(genderLabel, 0, 5);
        gridPane.add(genderText, 1, 5);
        gridPane.add(addressLabel, 0, 6);
        gridPane.add(addressText, 1, 6);
        gridPane.add(telNumLabel, 0, 7);
        gridPane.add(telNumText, 1, 7);
    }


}
